﻿Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
        'Dim str As String
        'str = "insert into message(receiver,sender,message,date) values('" + DropDownList1.SelectedValue + "','" + Session("username") + "','" + TextBox1.Text.Trim() + "','" + DateTime.Now.Date + "')"
        '
        'Dim cmd As New SqlCommand(str, cn)
        'Try
        'cn.Open()
        '
        'If cmd.ExecuteNonQuery = 1 Then
        ' Label3.Text = "Message Send"
        'Else
        'Label3.Text = "Error Occured ! Try after some time..."
        'End If
        '
        'Catch ex As Exception
        'Label3.Text = "Error Occured ! Try after some time..."
        'End Try
        Try
            Dim x As Integer
            ' x = functions.sendmessage("insert into message(receiver,sender,message,date) values('" + DropDownList1.SelectedValue + "','" + Session("username") + "','" + TextBox1.Text.Trim() + "','" + DateTime.Now.Date + "')")
            x = functions.sendmessage("insert into message(receiver,sender,message,date) values('" + DropDownList1.SelectedValue + "','" + Session("username") + "','" + TextBox1.Text.Replace("'", "''").Trim() + "','" + DateTime.Now.Date + "')")
            If x = 1 Then
                Label3.Text = "Message Send"
            Else
                Label3.Text = "Error Occured ! Try after some time..."
            End If
        Catch ex As Exception
            Label3.Text = "Error Occured ! Try after some time..."
        End Try


    End Sub


    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        ' Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
        ' Dim str As String
        ' str = "delete from message where msgid=" + GridView1.Rows(GridView1.SelectedRow.RowIndex).Cells(0).Text
        '
        '        Dim cmd As New SqlCommand(str, cn)
        '        Try
        ' cn.Open()
        ' cmd.ExecuteNonQuery()
        ' cn.Close()
        ' Catch ex As Exception
        ' Label3.Text = "Error Occured ! Try after some time..."
        ' End Try
        '
        '        ' aa stat autopost bakc nai thatu mate.deleteni aeffect mate
        '        Response.Redirect("messages.aspx")
        Try
            Dim str As String
            str = "delete from message where msgid=" + GridView1.Rows(GridView1.SelectedRow.RowIndex).Cells(0).Text
            functions.delmessages(str)
        Catch ex As Exception
            Label3.Text = "Error Occured ! Try after some time..."
        End Try
        Response.Redirect("messages.aspx")

    End Sub

    Protected Sub Button1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Load


        If Session("username") = "Guest" Then
            Response.Redirect("login.aspx")
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label2.Text = Session("username")
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

    End Sub
End Class
